package com.aso114.project.mvp.activity.fragment;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aso114.project.R;
import com.aso114.project.adapter.ChapterContactAdapter;
import com.aso114.project.adapter.GridAdapter;
import com.aso114.project.base.BaseFragment;
import com.aso114.project.bean.BannerBean;
import com.aso114.project.bean.CourseBean;
import com.aso114.project.bean.QuestionBean;
import com.aso114.project.bean.QuestionUserListBean;
import com.aso114.project.commonview.CustomDatePicker;
import com.aso114.project.commonview.MyGridView;
import com.aso114.project.exam.ExpositionTestActivity;
import com.aso114.project.exam.QuestionTestActivity;
import com.aso114.project.mvp.LoginSP;
import com.aso114.project.mvp.activity.BannerDetaiActivity;
import com.aso114.project.mvp.activity.ChapterContactActivity;
import com.aso114.project.mvp.activity.ChoiceExamActivity;
import com.aso114.project.mvp.activity.EeeorExerciseActivity;
import com.aso114.project.mvp.activity.ExamResultsActivity;
import com.aso114.project.mvp.activity.LoginActivity;
import com.aso114.project.mvp.activity.MyCollectActivity;
import com.aso114.project.mvp.activity.NeedNoticeDetailActivity;
import com.aso114.project.mvp.activity.PracticeHistoryActivity;
import com.aso114.project.mvp.activity.SatPracticeTestActivity;
import com.aso114.project.mvp.model.CallBack;
import com.aso114.project.mvp.model.CommentModel;
import com.aso114.project.util.Constant;
import com.aso114.project.util.Helper;
import com.aso114.project.util.SpfUtil;
import com.aso114.project.util.SystemBarHelper;
import com.aso114.project.util.Timeutils;
import com.aso114.project.util.ToastUtils;
import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.bumptech.glide.Glide;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;

import org.greenrobot.eventbus.EventBus;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 行测
 */
public class AdministrarAptitudeTestFragment extends BaseFragment implements OnItemClickListener,
        View.OnClickListener {

    @BindView(R.id.home_liatView)
    SwipeMenuRecyclerView homeLiatView;
    Unbinder unbinder;

    ConvenientBanner convenientBanner;
    MyGridView gridview;
    TextView homeDay1, homeDay2, homeDay3;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    private static ArrayList<CourseBean> courseBeans;
    @BindView(R.id.layout_title_bar_title_tv)
    TextView layoutTitleBarTitleTv;
    @BindView(R.id.title_left_tv)
    TextView titleLeftTv;
    @BindView(R.id.ic_scan)
    ImageView icScan;
    @BindView(R.id.title_right_tv)
    TextView titleRightTv;
    @BindView(R.id.layout_title_bar_right_iv)
    ImageView layoutTitleBarRightIv;
    @BindView(R.id.yuedu)
    ImageView yuedu;
    @BindView(R.id.title_top_ly)
    RelativeLayout titleTopLy;
    private CustomDatePicker datePicker;
    private String date;
    private int starYear;
    private List<BannerBean> bannerList = new ArrayList<>();
    ChapterContactAdapter chapterContactAdapter;
    Dialog dialog;
    private List<QuestionUserListBean> listBean = new ArrayList<>();
    //定义图标数组
    private int[] imageRes = {
            R.mipmap.home_kd_ic,
            R.mipmap.home_zj_ic,
            R.mipmap.home_zt_ic,
            R.mipmap.home_gg_ic,
            R.mipmap.home_ks_ic,
            R.mipmap.home_lx_ic,
            R.mipmap.home_ct_ic,
            R.mipmap.home_sc_ic};

    //定义图标下方的名称数组
    private String[] name = {
            "考点练习",
            "章节练习",
            "真题模考",
            "巩固模考",
            "考试成绩",
            "练习历史",
            "错题练习",
            "收藏题"
    };

    private GridAdapter adapter;
    Intent intent;
    QuestionBean qdata;
    public int position;
    private String typeid;
    Animation animation;

    public static AdministrarAptitudeTestFragment newInstance(int position, String typeid) {
        Bundle args = new Bundle();
//        System.out.println("进入的===" + position);
        args.putInt("position", position);
        args.putString("typeid", typeid);
//        args.putSerializable("dataList", (Serializable) datatype);
        AdministrarAptitudeTestFragment fragment = new AdministrarAptitudeTestFragment();
        fragment.setArguments(args);
//        fragment.position = position;
        return fragment;
    }

    @Override
    protected int getLayoutResourceId() {
        return R.layout.administraraptitudetest;
    }

    @Override
    protected void initView() {
        SystemBarHelper.immersiveStatusBar(getActivity());
        SystemBarHelper.setHeightAndPadding(getActivity(), titleTopLy);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            SystemBarHelper.immersiveStatusBar(getActivity(), 0);
            SystemBarHelper.setStatusBarDarkMode(getActivity());
        }
        layoutTitleBarTitleTv.setText("题  库");

        if (!Constant.isUserAreaId) {
            LoginSP.getInstance().setUserAreaId("36");//不分地区都为36
            titleLeftTv.setVisibility(View.GONE);
        }

        if (LoginSP.getInstance().getCityname().equals("")) {
            titleLeftTv.setText("厦门");
        } else {
            String city_name = LoginSP.getInstance().getCityname().replace("考", "");
            titleLeftTv.setText(city_name);
        }

        Drawable drawable = getActivity().getResources().getDrawable(R.mipmap.home_xia_ic);
        // 这一步必须要做,否则不会显示.
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        titleLeftTv.setCompoundDrawables(null, null, drawable, null);

        layoutTitleBarRightIv.setImageResource(R.mipmap.home_cj_ic);
        animation = AnimationUtils.loadAnimation(getActivity(), R.anim.img_animation);
        LinearInterpolator lin = new LinearInterpolator();//设置动画匀速运动
        animation.setInterpolator(lin);
        layoutTitleBarRightIv.startAnimation(animation);
        titleRightTv.setText("成绩");
        titleRightTv.setVisibility(View.VISIBLE);
        layoutTitleBarRightIv.setVisibility(View.VISIBLE);

        courseBeans = getCategoryBeans();
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        tabLayout.setSelectedTabIndicatorHeight(0);
        for (int i = 0; i < courseBeans.size(); i++) {
            //添加tab
            tabLayout.addTab(tabLayout.newTab().setText(courseBeans.get(i).getTitle()));
        }

        for (int i = 0; i < tabLayout.getTabCount(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            if (tab != null) {
                tab.setCustomView(getTabView(i));
            }

            if (i == 0) {
                updateTabTextView(tabLayout.getTabAt(0), true);

            } else {
                updateTabTextView(tab, false);
            }
        }


        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {

                updateTabTextView(tab, true);

                Constant.position = tab.getPosition();
                Constant.adutst = Constant.titleTypeNum[tab.getPosition()];
                Constant.essay = Constant.titleTypeNum[tab.getPosition()];
                String typeid = courseBeans.get(tab.getPosition()).getData_type();
//                Constant.adutst = typeid;
                System.out.println("题库id===" + Constant.position);


                getData(typeid);

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                updateTabTextView(tab, false);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                //选中之后再次点击即复选时触发

            }
        });
//        System.out.println("题库大小id===" + typeid + "====" + "position" + position+"===="+MainIndexFragment.courseBeans.get(position).getTitle());
        homeLiatView.setLayoutManager(new LinearLayoutManager(getActivity()));
        View headerView = getLayoutInflater().inflate(R.layout.home_header, homeLiatView, false);
        convenientBanner = headerView.findViewById(R.id.convenientBanner);
        gridview = headerView.findViewById(R.id.gridview);
        headerView.findViewById(R.id.currentDate).setOnClickListener(this);
        homeDay1 = headerView.findViewById(R.id.home_day1);
        homeDay2 = headerView.findViewById(R.id.home_day2);
        homeDay3 = headerView.findViewById(R.id.home_day3);
        homeLiatView.addHeaderView(headerView);
        getData(Constant.titleTypeNum[0]);
        getType();
        initPicker();
        chapterContactAdapter = new ChapterContactAdapter();
        homeLiatView.setAdapter(chapterContactAdapter);
        chapterContactAdapter.setDatas(listBean);
        chapterContactAdapter.setItemClick(new ChapterContactAdapter.OnItemClick() {
            @Override
            public void click(String id) {
                // 点击章节练习  进入练习试卷
                final View dialogview = getActivity().getLayoutInflater().inflate(
                        R.layout.loading_view, null);
                dialog = new Dialog(getActivity(), R.style.dialogStyle);
                dialog.setContentView(dialogview, new ViewGroup.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                dialog.getWindow().setGravity(Gravity.CENTER);
                // 设置点击外围解散
                dialog.setCanceledOnTouchOutside(true);
                dialog.setCancelable(true);//设置是否可以按退回键取消
                dialog.show();
                // 点击章节练习  进入练习试卷
                CommentModel.getInstant().get_chapter_bank(LoginSP.getInstance().getUserAreaId(),
                        id, new CallBack() {
                            @Override
                            public void onSuccess(Object o, boolean isSuccess, String msg) {
                                dialog.cancel();
                                Helper.gotoLogin(isSuccess);//token失效去重新登陆
                                qdata = (QuestionBean) o;

                                System.out.println("题库大小111===" + qdata.getPaperTitle());
                                //getQuestionBaseList()
                                // .get(0).getQuestionList().size()

                                System.out.println("题库数组大小===" + qdata.getQuestionBaseList().get(0)
                                        .getQuestionList().size());


                                EventBus.getDefault().postSticky(qdata);

                                Constant.title_tv = "2";
                                intent = new Intent(getActivity(), QuestionTestActivity.class);
                                intent.putExtra("is_exam", true);
                                startActivity(intent);
                            }

                            @Override
                            public void onFailure(String fail) {
                                ToastUtils.showToast(getActivity(), "获取题库失败");
                                dialog.cancel();
                            }
                        });
            }
        });

    }


    private void getData(String typeid) {

        bannerList.clear();
        CommentModel.getInstant().getAptiudeTest_banner(typeid, "1", new CallBack() {
            @Override
            public void onSuccess(Object o, boolean isSuccess, String msg) {
                Helper.gotoLogin(isSuccess);//token失效去重新登陆
                bannerList = (List<BannerBean>) o;

                System.out.println("banner数组大小===" + bannerList.size());

                initBanner();

            }

            @Override
            public void onFailure(String fail) {
//                bannerList = new ArrayList<>();
                BannerBean bn = new BannerBean();

                bn.setLitpic("https://timgsa.baidu" +
                        ".com/timg?image&quality=80&size=b9999_10000&sec=1543408736304&di" +
                        "=a4bfe0ca275ca305834a525c18cd231d&imgtype=0&src=http%3A%2F" +
                        "%2F5b0988e595225.cdn.sohucs" +
                        ".com%2Fimages%2F20181120%2F9c4edc6604e84eba863c75f2e6cd7221.jpeg");
                bannerList.add(bn);
                BannerBean bn1 = new BannerBean();
                bn1.setLitpic("https://timgsa.baidu" +
                        ".com/timg?image&quality=80&size=b9999_10000&sec=1543408563496&di" +
                        "=cbef8feab19013ac5f3b9507a62f75f7&imgtype=0&src=http%3A%2F%2Fd.ifengimg" +
                        ".com%2Fw600%2Fp0.ifengimg" +
                        ".com%2Fpmop%2F2018%2F1105%2F061500E3A7CFE1AA91524E97BEFE84D6A09FE7B7_size98_w1000_h562.jpeg");
                bannerList.add(bn1);

                System.out.println("banner数组大小===" + bannerList.size());
                initBanner();
            }
        });


        CommentModel.getInstant().getSpecialTreeList(typeid, new CallBack() {
            @Override
            public void onSuccess(Object o, boolean isSuccess, String msg) {
                Helper.gotoLogin(isSuccess);//token失效去重新登陆
                List<QuestionUserListBean> bean = (List<QuestionUserListBean>) o;
                listBean.clear();
                if (bean == null || bean.size() == 0) {
                    return;
                }
                listBean = bean;
                chapterContactAdapter.setDatas(bean);
                chapterContactAdapter.notifyDataSetChanged();
            }

            @Override
            public void onFailure(String fail) {

            }
        });
    }

    public static ArrayList<CourseBean> getCategoryBeans() {
        ArrayList<CourseBean> beans = new ArrayList<>();

        for (int i = 0; i < Constant.titleType.length; i++) {

            beans.add(new CourseBean(Constant.titleType[i], Constant.titleTypeNum[i]));

        }


        return beans;
    }

    private void initBanner() {
        convenientBanner.setPages(new CBViewHolderCreator<NetworkImageHolderView>() {
            @Override
            public NetworkImageHolderView createHolder() {
                return new NetworkImageHolderView();
            }
        }, bannerList);
        convenientBanner.setPointViewVisible(true)//设置指示器是否可见
                //设置自动切换（同时设置了切换时间间隔）
                .startTurning(3000)
                //设置两个点图片作为翻页指示器，不设置则没有指示器，可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
                .setPageIndicator(new int[]{R.mipmap.ej_sjkbai_ic, R.mipmap.ej_sjk_ic})
                //设置指示器的方向（左、中、右）
                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL)
                //设置点击监听事件
                .setOnItemClickListener(this)
                //设置手动影响（设置了该项无法手动切换）
                .setManualPageable(true);
        if (bannerList.size() > 1) {
            convenientBanner.setCanLoop(true);
            convenientBanner.setPointViewVisible(true);
        } else {
            convenientBanner.setCanLoop(false);
            convenientBanner.setPointViewVisible(false);
        }
    }

    /**
     * banner item点击事件
     */
    @Override
    public void onItemClick(int position) {
        // 获取banner  type
        int type = Integer.valueOf(bannerList.get(position).getLinktype());

        switch (type) {
            case 0:// 无跳转
                break;
            case 1:// 链接
                intent = new Intent(getActivity(), BannerDetaiActivity.class);
                intent.putExtra("linkUrl", bannerList.get(position).getLinkurl());
                startActivity(intent);
                break;
            case 2:// 题库
                final String[] id = bannerList.get(position).getLinkurl().split(",");
                //[考题ID，行测或申论ID，考区ID]
                View dialogview = getActivity().getLayoutInflater().inflate(
                        R.layout.loading_view, null);
                dialog = new Dialog(getActivity(), R.style.dialogStyle);
                dialog.setContentView(dialogview, new ViewGroup.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                dialog.getWindow().setGravity(Gravity.CENTER);
                // 设置点击外围解散
                dialog.setCanceledOnTouchOutside(true);
                dialog.setCancelable(true);//设置是否可以按退回键取消
                dialog.show();
                Constant.title_tv = "3";
                CommentModel.getInstant().get_question_bank(id[2], id[0], id[1], new CallBack() {
                    @Override
                    public void onSuccess(Object o, boolean isSuccess, String msg) {
                        dialog.cancel();
                        Helper.gotoLogin(isSuccess);//token失效去重新登陆
                        QuestionBean qdata = (QuestionBean) o;

                        EventBus.getDefault().postSticky(qdata);
                        if (Constant.adutst.equals(id[1])) {//行测
                            //行测
                            intent = new Intent(getActivity(), QuestionTestActivity.class);
                            intent.putExtra(QuestionTestActivity.IS_EXAM, true);

                        }
                        if (Constant.essay.equals(id[1])) {//申论
                            //申论
                            intent = new Intent(getActivity(), ExpositionTestActivity.class);

                        }
                        startActivity(intent);

                    }

                    @Override
                    public void onFailure(String fail) {
                        Helper.showToast("获取题库失败");
                        dialog.cancel();
                    }
                });
                break;
            case 3:// 页面（须知）
                intent = new Intent(getContext(), NeedNoticeDetailActivity.class);
                intent.putExtra("type", bannerList.get(position).getLinkurl());
                startActivity(intent);
                break;

        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
            savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onResume() {
        super.onResume();
        SystemBarHelper.immersiveStatusBar(getActivity());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            SystemBarHelper.immersiveStatusBar(getActivity(), 0);
            SystemBarHelper.setStatusBarDarkMode(getActivity());
        }
        layoutTitleBarRightIv.startAnimation(animation);
        if (LoginSP.getInstance().getCityname().equals("")) {
            titleLeftTv.setText("厦门");
        } else {

            if (LoginSP.getInstance().getCityname().equals("国考")) {
                titleLeftTv.setText("国考");
            } else {
                String city_name = LoginSP.getInstance().getCityname().replace("考", "");
                titleLeftTv.setText(city_name);
            }

        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    private View getTabView(int currentPosition) {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.tab_item, null);
        TextView textView = (TextView) view.findViewById(R.id.tab_item_textview);
        textView.setText(courseBeans.get(currentPosition).getTitle());
        return view;
    }

    private void updateTabTextView(TabLayout.Tab tab, boolean isSelect) {

        if (isSelect) {
            //选中加粗
            TextView tabSelect = (TextView) tab.getCustomView().findViewById(R.id.tab_item_textview);
            tabSelect.setTextColor(getResources().getColor(R.color.redcolor));
            tabSelect.setTextSize(18);
            tabSelect.setText(tab.getText());
        } else {
            TextView tabUnSelect = (TextView) tab.getCustomView().findViewById(R.id.tab_item_textview);
            tabUnSelect.setTextSize(15);
            tabUnSelect.setTextColor(getResources().getColor(R.color.black333));
            tabUnSelect.setText(tab.getText());
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.currentDate:
                datePicker.show(date);
                break;
        }
    }

    @OnClick({R.id.title_left_tv, R.id.layout_title_bar_right_iv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_left_tv:
                intent = new Intent(getContext(), ChoiceExamActivity.class);
                startActivity(intent);
                break;
            case R.id.layout_title_bar_right_iv:
                //考试成绩
                intent = new Intent(getContext(), ExamResultsActivity.class);
                intent.putExtra("type", "30");
                startActivity(intent);
                break;
        }
    }


    public class NetworkImageHolderView implements Holder<BannerBean> {
        private ImageView imageView;

        @Override
        public View createView(Context context) {
            imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            return imageView;
        }

        @Override
        public void UpdateUI(Context context, int position, BannerBean data) {
            Glide.with(getActivity()).load(data.getLitpic()).into(imageView);
        }

    }

    /**
     * gridview  的  adapter
     */
    private void getType() {
        adapter = new GridAdapter(imageRes, name);
        gridview.setAdapter(adapter);
        //添加消息处理
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                Toast.makeText(getActivity(), name[position], Toast.LENGTH_LONG).show();

                if (position == 0) {


                    if (TextUtils.isEmpty(LoginSP.getInstance().getToken())) {
                        ToastUtils.showToast(getActivity(), "您还未登陆,请先登陆");
                        intent = new Intent(getContext(), LoginActivity.class);
                        startActivity(intent);
                        return;
                    }

                    Constant.title_tv = "1";
                    View dialogview = getActivity().getLayoutInflater().inflate(
                            R.layout.loading_view, null);
                    dialog = new Dialog(getActivity(), R.style.dialogStyle);
                    dialog.setContentView(dialogview, new ViewGroup.LayoutParams(
                            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams
                            .WRAP_CONTENT));
                    dialog.getWindow().setGravity(Gravity.CENTER);
                    // 设置点击外围解散
                    dialog.setCanceledOnTouchOutside(true);
                    dialog.setCancelable(true);//设置是否可以按退回键取消
                    dialog.show();

                    CommentModel.getInstant().get_testing_bank(LoginSP.getInstance()
                            .getUserAreaId(), Constant.adutst, new CallBack() {
                        @Override
                        public void onSuccess(Object o, boolean isSuccess, String msg) {

                            dialog.cancel();
                            Helper.gotoLogin(isSuccess);//token失效去重新登陆
                            qdata = (QuestionBean) o;

                            EventBus.getDefault().postSticky(qdata);

                            intent = new Intent(getActivity(), QuestionTestActivity.class);
                            intent.putExtra("is_exam", false);
                            intent.putExtra("isAnalysis", true);

                            startActivity(intent);

                        }

                        @Override
                        public void onFailure(String fail) {
                            ToastUtils.showToast(getActivity(), "获取题库失败");
                            dialog.cancel();
                        }
                    });


                }


                if (position == 1) {
                    if (TextUtils.isEmpty(LoginSP.getInstance().getToken())) {
                        ToastUtils.showToast(getActivity(), "您还未登陆,请先登陆");
                        intent = new Intent(getContext(), LoginActivity.class);
                        startActivity(intent);
                        return;
                    }
                    Constant.title_tv = "2";
                    startActivity(new Intent(getContext(), ChapterContactActivity.class));
                }
                if (position == 2) {
                    if (TextUtils.isEmpty(LoginSP.getInstance().getToken())) {
                        ToastUtils.showToast(getActivity(), "您还未登陆,请先登陆");
                        intent = new Intent(getContext(), LoginActivity.class);
                        startActivity(intent);
                        return;
                    }
                    Constant.title_tv = "3";
                    //真题模考
                    intent = new Intent(getContext(), SatPracticeTestActivity.class);
                    intent.putExtra("type", "1");
                    intent.putExtra("catid", Constant.adutst);
                    startActivity(intent);
                }
                if (position == 3) {
                    if (TextUtils.isEmpty(LoginSP.getInstance().getToken())) {
                        ToastUtils.showToast(getActivity(), "您还未登陆,请先登陆");
                        intent = new Intent(getContext(), LoginActivity.class);
                        startActivity(intent);
                        return;
                    }
                    Constant.title_tv = "4";
                    //巩固模考
                    intent = new Intent(getContext(), SatPracticeTestActivity.class);
                    intent.putExtra("type", "30");
                    startActivity(intent);
                }
                if (position == 4) {
                    if (TextUtils.isEmpty(LoginSP.getInstance().getToken())) {
                        ToastUtils.showToast(getActivity(), "您还未登陆,请先登陆");
                        intent = new Intent(getContext(), LoginActivity.class);
                        startActivity(intent);
                        return;
                    }
                    Constant.title_tv = "5";
                    //考试成绩
                    intent = new Intent(getContext(), ExamResultsActivity.class);
                    intent.putExtra("position", Constant.position);
                    startActivity(intent);
                }
                if (position == 5) {
                    if (TextUtils.isEmpty(LoginSP.getInstance().getToken())) {
                        ToastUtils.showToast(getActivity(), "您还未登陆,请先登陆");
                        intent = new Intent(getContext(), LoginActivity.class);
                        startActivity(intent);
                        return;
                    }
                    Constant.title_tv = "6";
                    // 练习历史
                    intent = new Intent(getContext(), PracticeHistoryActivity.class);
                    intent.putExtra("position", Constant.position);
                    startActivity(intent);
                }
                if (position == 6) {
                    if (TextUtils.isEmpty(LoginSP.getInstance().getToken())) {
                        ToastUtils.showToast(getActivity(), "您还未登陆,请先登陆");
                        intent = new Intent(getContext(), LoginActivity.class);
                        startActivity(intent);
                        return;
                    }
                    Constant.title_tv = "7";
                    //错题练习
                    intent = new Intent(getContext(), EeeorExerciseActivity.class);
                    intent.putExtra("position", Constant.position);
                    startActivity(intent);
                }
                if (position == 7) {
                    if (TextUtils.isEmpty(LoginSP.getInstance().getToken())) {
                        ToastUtils.showToast(getActivity(), "您还未登陆,请先登陆");
                        intent = new Intent(getContext(), LoginActivity.class);
                        startActivity(intent);
                        return;
                    }
                    Constant.title_tv = "8";
                    //收藏题
                    intent = new Intent(getContext(), MyCollectActivity.class);//
                    intent.putExtra("position", Constant.position);
                    startActivity(intent);
                }


            }
        });
    }


    private void initPicker() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        date = sdf.format(new Date());
        starYear = Integer.valueOf(date.split("-")[0]);
        //设置当前显示的日期
//        currentDate.setText(date);

        String endTime = SpfUtil.getInstance().getString("dayTime", "2018-01-01");
        dayNum(endTime);

        /**
         * 设置年月日
         */
        /**
         * 设置年月日
         */
        datePicker = new CustomDatePicker(getActivity(), "考试时间", new CustomDatePicker
                .ResultHandler() {
            @Override
            public void handle(String time) throws ParseException {
                dayNum(time.split(" ")[0]);
                SpfUtil.getInstance().putString("dayTime", time.split(" ")[0]);
            }

        }, starYear + "-01-01 00:00", (starYear + 2) + "-12-31 23:59");
        datePicker.showSpecificTime(false); //显示时和分
        datePicker.setIsLoop(true);


    }

    private void dayNum(String time) {
        long starTime = Timeutils.getStringToDate(date, "yyyy-MM-dd");
        long endTime = Timeutils.getStringToDate(time, "yyyy-MM-dd");
        long dayTime = endTime - starTime;
        long day = dayTime / (24 * 60 * 60 * 1000);
        if (day < 0) {
            day = 0;
        }
        String daystr = String.format("%03d", day);
        homeDay1.setText(daystr.substring(0, 1));
        homeDay2.setText(daystr.substring(1, 2));
        homeDay3.setText(daystr.substring(2));
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void addOnClick() {

    }

}